﻿CREATE PROCEDURE [dbo].[UserAccount_InsertUpdate]

	@id					BIGINT,

	@name				VARCHAR (0060), 

	@description		VARCHAR (0999),


	@securityAuthorityId		BIGINT,

	@distinguishedName			VARCHAR (0999),

	@displayName				VARCHAR (0060),


	@modifiedId					VARCHAR (0060)

AS

	BEGIN 

		MERGE UserAccount

			USING (SELECT @id) AS Source (Id)

				ON UserAccount.Id = Source.Id

			WHEN MATCHED THEN 

				UPDATE SET 

					Name = @name,

					Description = @description,

					SecurityAuthorityId = @securityAuthorityId,

					DistinguishedName = @distinguishedName,

					DisplayName = @displayName,

					ModifiedId = @modifiedId,

					ModifiedDateTime = GETDATE ()

			WHEN NOT MATCHED THEN 

				INSERT (Name, Description, SecurityAuthorityId, DistinguishedName, DisplayName, CreateId, CreateDateTime, ModifiedId, ModifiedDateTime) 

					VALUES (@name, @description, @securityAuthorityId, @distinguishedName, @displayName, @modifiedId, GETDATE (), @modifiedId, GETDATE())

		; -- MERGE ( END )


	END
